package com.woniu.controller;

import com.woniu.pojo.User;
import com.woniu.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/loginController")
public class LoginController {
    @Autowired
    private UserService userService;
    private Logger logger=Logger.getLogger(this.getClass());

    @PostMapping(value = "/login")
    public ModelAndView login(@RequestParam("username")String telephone,@RequestParam("password")String password, HttpSession session){
        logger.debug(telephone);
        logger.debug(password);
        User user=userService.findUserByUid(telephone,password);

        ModelAndView modelAndView=new ModelAndView();
        session.setAttribute("user",user);
        modelAndView.setViewName("/index.jsp");
        return  modelAndView;
    }
}
